const pool = require('./db.js')
class farmlandDao{
  async getFarmlandByID(id){
    try {
      let result = pool.execute('select * from farmland where id=?',[id])
      return result
    }catch(err){
      console.log("出错："+err)
    }
  }
  async getAllFarmland(){
    try{
      let result = pool.execute('select * from farmland')
      return result
    }catch(err){
      console.log("出错："+err)
    }
  }
  // 添加农田
  async addFarmland(name,type,manager_id){
    try{
      let result = pool.execute('insert farmland(farmland_name,farmland_type,manager_id) values(?,?,?) ',[name,type,manager_id])
      return result
    }catch(err){
      console.log("出错："+err)
    }
  }
  // 修改农田
  async modifyFarmland(id,name,type,manager_id){
    try{
      let result = pool.execute('update farmland set farmland_name=?,farmland_type=?,manager_id=? where id=?',[name,type,manager_id,id])
      return result
    }catch(err){
      console.log("出错："+err)
    }
  }
  // 删除农田
  async deleteFarmland(id){
    try{
      let result = pool.execute('delete from farmland where id=?',[id])
      return result
    }catch(err){
      console.log("出错："+err)
    }
  }
}
module.exports = new farmlandDao()